package com.hs.controller;


import com.github.pagehelper.PageInfo;
import com.hs.entity.RestBean;
import com.hs.entity.dto.Comment;
import com.hs.entity.dto.TeamEmp;
import com.hs.service.CommentService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/comment")
public class CommentController {

    @Resource
    private CommentService commentService;

    @GetMapping("/getCommentList/{currentNum}")
    public RestBean<PageInfo<Comment>> getCommentList(
            @PathVariable("currentNum") Integer currentNum,
            @RequestParam(required = false) String keywords) {
        PageInfo<Comment> commentList = commentService.selectCommentList(currentNum,keywords);
        return RestBean.success(commentList);
    }

    @GetMapping("/getCommentListByTeamId/{currentNum}/{teamId}")
    public RestBean<PageInfo<Comment>> getCommentListByTeamId(
            @PathVariable("currentNum") Integer currentNum,
            @PathVariable("teamId") Integer teamId) {
        PageInfo<Comment> commentList = commentService.selectCommentListByTeamId(currentNum,teamId);
        return RestBean.success(commentList);
    }

    @GetMapping("/getAllCommentByTeamId/{teamId}")
    public RestBean<List<Comment>> getAllCommentByTeamId(@PathVariable  Integer teamId) {
        List<Comment> commentListByTeamId = commentService.selectAllCommentListByTeamId(teamId);
        return RestBean.success(commentListByTeamId);
    }

    @PostMapping("/updateComment")
    public RestBean<Comment> updateComment( @RequestBody Comment comment) {
        System.out.println(comment);
        comment.setStatus(1);
        commentService.updateById(comment);
        return RestBean.success(null);
    }

    @PostMapping("/addComment")
    public RestBean<Comment> addComment( @RequestBody Comment comment) {
        comment.setCreate_time(LocalDateTime.now());
        commentService.save(comment);
        return RestBean.success(null);
    }

    @PostMapping("/deleteComment/{id}")
    public RestBean<Comment> deleteComment(@PathVariable  Integer id) {
        commentService.removeById(id);
        return RestBean.success(null);
    }
    @PostMapping("/like/{id}")
    public RestBean<Comment> likeComment(@PathVariable  Integer id) {
        commentService.likeComment(id);
        return RestBean.success(null);
    }

}
